package org.yxing.palpalgps.image;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;

import android.graphics.Bitmap;

public class ImageCache {
	private Map<String, SoftReference<Bitmap>> mSoftCache;
	
	public ImageCache() {
		mSoftCache = new HashMap<String, SoftReference<Bitmap>>();
	}
	
	public Bitmap get(String url) {
		Bitmap bitmap = null;
		
		SoftReference<Bitmap> ref = mSoftCache.get(url);
		if (ref != null) {
			bitmap = ref.get();
			if (bitmap == null)
				mSoftCache.remove(url);
		}
		
		return bitmap;
	}
	
	public void put(String url, Bitmap bitmap) {
		mSoftCache.put(url, new SoftReference<Bitmap>(bitmap));
	}
	
	public void clear() {
		mSoftCache.clear();
	}
}
